package com.o2o.sphinx;

import com.o2o.sphinx.SphinxClient;
import com.o2o.sphinx.SphinxException;

public class SortUtil {
	
	public static final int HOT_DESC = 1;
	public static final int DATA_DESC = 2;
	public static final int MATCH_DESC = 3;
	public static final int ATTR_EXTENDED = 4;
	
	
	public static SphinxClient getSphinx(SphinxClient cl,int sort,String name) throws SphinxException{
		cl.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED);
			if(sort == HOT_DESC){
				cl.SetSortMode(SphinxClient.SPH_SORT_ATTR_DESC,"topic_hot");
			}else
			if(sort == MATCH_DESC){
				cl.SetSortMode(SphinxClient.SPH_SORT_EXTENDED  ,"@weight DESC,topic_hot desc, @id ASC");//按最好的匹配排在前面
			}else
			if(sort == DATA_DESC){
				cl.SetSortMode(SphinxClient.SPH_SORT_EXTENDED ,"topic_create_time DESC");
			}else
				cl.SetSortMode(SphinxClient.SPH_SORT_EXTENDED  ,"@weight DESC,topic_hot desc, @id ASC");//按最好的匹配排在前面
			if(sort == ATTR_EXTENDED){
				cl.SetSortMode(SphinxClient.SPH_SORT_EXTENDED  ,name);
			}
			return cl;
	}

}
